﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;
using KPIS.GERP.ESS.BLL;
using KPIS.GERP.ESS.MODEL;

namespace KPIS.GERP.ESS.APP.App_UI.Forms
{
    public partial class RequestChanges : System.Web.UI.Page
    {
        private B_HrmRequest reqBLL = new B_HrmRequest();
        private B_MessageSend sendBLL = new B_MessageSend();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["EmpSeq"] = "60";
                ViewGrid();
            }            
        }
        public void ViewGrid()
        {
            LoadDataGrid();
            PanelFilter.Visible = true;
            PanelPersonal.Visible = false;
            chgPersonal1.Visible = false;

            if (PanelPersonal.Visible)
                lblHeader.Text = "แบบฟอร์มคำร้อง";
            else
                lblHeader.Text = "รายการคำร้อง";
        }
        public void LoadDataGrid()
        {
            DataSet ds = reqBLL.GetRequestChange((int?)null, Int32.Parse(Session["EmpSeq"].ToString()), "");
            DataTable dt = null;

            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                RadGrid1.DataSource = dt;
                RadGrid1.DataBind();
            }
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "NewInsert")
            {
                //int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["send_seq"]);

                PanelFilter.Visible = false;
                PanelMain.Visible = true;
                PanelPersonal.Visible = false;
                chgPersonal1.Visible = false;
                //chgPersonal1.LoadDataEditInsert(0);
            }
            else if (e.CommandName == "Delete")
            {
                int Sequence = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["chg_reg_seq"]);

                // ลบ Table Request ก่อน
                reqBLL.DeleteRequestChanges(Sequence, Int32.Parse(Session["EmpSeq"].ToString()));
                
            }
            else if (e.CommandName == "ShowDetail" && e.Item is GridDataItem)
            {
                int Sequence = Int32.Parse(RadGrid1.Items[e.Item.ItemIndex]["chg_emp_seq"].Text);

                PanelFilter.Visible = false;
                PanelPersonal.Visible = true;
                chgPersonal1.Visible = true;
                chgPersonal1.LoadDataView(Sequence);
            }
            LoadDataGrid();
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            LoadDataGrid();
        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            chgPersonal1.Visible = true;
            chgPersonal1.LoadDataView(1);
        }
    }
}
